const express = require('express'),
    db = require('../db'),
    router = express();

router.post('/', (req, res, next) => {
    let user = {createTime: new Date(), updateTime: new Date()};
    user = Object.assign(req.body, user);
    db.User.find({username: req.body.username}).exec((err, data) => {
        if (data.length > 0) {
            res.json({code: "error", message: "用户名已存在!"});
        } else {
            new db.User(user).save(function (err) {
                if (err) {
                    res.json({code: "error", message: "注册失败!"});
                } else {
                    res.json({code: "success", message: "注册成功！"});
                }
            })
        }
    })


})
module.exports = router;